/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.assets.shooterstates;

import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.templates.assets.statemachine.State;
import edu.wpi.first.wpilibj.templates.assets.statemachine.StateMachine;
import edu.wpi.first.wpilibj.templates.commands.CommandBase;

/**
 *
 * @author Jarrod Risley
 */
public class ShootState extends State {

    /*
     * Global Class Variables
     */
    protected static ShootState SHOOT_STATE =
            new ShootState("Shoot State");
    
    private double startTime;
    private boolean shooterRampedUp = false;
    
    private static final double TIMEOUT_TIME = 1;
    
    // CONSTRUCTOR //
    
    
    private ShootState(String name) {
        super(name);
    }  // end ShootState Constructor
    
    protected void runFirst() {
        
        
        setNext(null);
        setTimeoutTimer(TIMEOUT_TIME);
        
    } // end runFirst

    protected void run() {
        
        startTime = Timer.getFPGATimestamp();
        
        do {
            
            CommandBase.shooter.indexerShoot();
            
            if (StateMachine.fallingEdge)
                CommandBase.shooter.decrementDiscCount();
            
        } while (startTime + 0.5 > Timer.getFPGATimestamp());
        
        CommandBase.shooter.indexerStop();
        
        if (Timer.getFPGATimestamp() > startTime + 2)
            MoveUpOne.MOVE_UP.resetTimesRun();
        
        if (!CommandBase.oi.getCoDriverController().getButtonRightTrigger())
            setFinished();
        else {
            
            setNext(ZingStateMachine.SPIN_UP_SHOOTER);
            
        } // end if-else
        
        setFinished();
        
    } // end run

    protected void runLast() {
    }

    protected boolean isFinished() {
        return getFinished();
    } // end isFinished

    protected void end() {
        
        CommandBase.shooter.stop();
        
    } // end end...lolz =P

    protected State getChainedInstance(State nextState) {
        
        SHOOT_STATE.setNext(nextState);
        return SHOOT_STATE;
        
    } // end getChainedInstance
    
} // end ShootState
